#!/usr/bin/env python3
import argparse
import requests

def main():
    # 解析命令行参数
    parser = argparse.ArgumentParser(description='HTTP client for brpc server')
    parser.add_argument('url', help='Server URL, e.g. "http://0.0.0.0:8000"')
    parser.add_argument('-d', '--data', default='world', help='POST data to the http server')
    parser.add_argument('--timeout', type=float, default=2.0, help='Request timeout in seconds')
    args = parser.parse_args()

    # 构建完整URL
    url = f"{args.url}/HttpService/Echo"

    try:
        # 发送POST请求
        response = requests.post(
            url,
            data=args.data,
            timeout=args.timeout
        )

        # 检查响应状态
        response.raise_for_status()

        # 打印响应
        print(f"Server response: {response.text}")

    except requests.exceptions.RequestException as e:
        print(f"Error: {e}")
        return 1

    return 0

if __name__ == '__main__':
    exit(main())
